package com.bobo.service.report;

import com.bobo.dao.report.IReportDao;
import com.bobo.dao.report.ReportDaoImpl;
import com.bobo.dto.Page;
import com.bobo.dto.ReportDto;
import com.bobo.model.Message;
import com.bobo.model.Report;
import com.bobo.model.Topic;
import com.bobo.model.User;

import java.util.List;

/**
 * Created by bobo on 16-11-3.
 */
public class ReportServiceImpl implements IReportService {
    IReportDao reportDao = new ReportDaoImpl();
    @Override
    public Integer create(Report report) {
        return reportDao.create(report);
    }

    @Override
    public boolean del(Integer id) {
        return reportDao.delete(id);
    }

    @Override
    public Report getById(Integer id) {
        return reportDao.getById(id);
    }

    @Override
    public Page<Report> getReports(Integer messageId,Integer current, Integer pageSize) {
        Page<Report> page = new Page<>();
        page.setCurrent(current);
        page.setPageSize(pageSize);
        Integer count = reportDao.getCount(messageId);
        float pagenum = count.floatValue()/pageSize.floatValue();
        page.setPageNum((int) Math.ceil(pagenum));
        page.setList(reportDao.getReports(messageId, current,pageSize));
        return page;
    }

    @Override
    public Page<ReportDto> getReportDtos(Integer current, Integer pageSize) {
        Page<ReportDto> page = new Page<>();
        page.setList(reportDao.getReportDtos(0,0));
        return page;
    }

    @Override
    public List<Message> getReportByUser(User user, Topic topic) {

        return reportDao.getReportByUser(user, topic);
    }
}
